<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 戴金睿
  Date: 2022/11/20
  Time: 16:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%--
公告板页面
--%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>EShopManager</title>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/lib/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/stylesheets/theme.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/lib/font-awesome/css/font-awesome.css"/>
    <script src="${pageContext.request.contextPath}/static/lib/jquery-1.7.2.min.js" type="text/javascript"></script>


    <!-- Demo page code -->

    <style type="text/css">
        #line-chart {
            height: 300px;
            width: 800px;
            margin: 0px auto;
            margin-top: 1em;
        }

        .brand {
            font-family: georgia, serif;
        }

        .brand .first {
            color: #ccc;
            font-style: italic;
        }

        .brand .second {
            color: #fff;
            font-weight: bold;
        }
    </style>

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="lib/html5.js"></script>
    <![endif]-->
</head>
<body>

<%--    第几页     --%>
<c:set var="page" scope="request">
    ${ param.page == null ? 1 : param.page }
</c:set>

<%--    顶部区域    --%>
<c:import url="top.jsp"></c:import>

<%--    左边区域    --%>
<c:import url="left.jsp"></c:import>


<!-- 内容区 -->
<div class="content">
    <div class="header">
        <h1 class="page-title">促销管理</h1>
    </div>

    <ul class="breadcrumb">
        <li><a href="adimg.jsp">促销管理</a> <span class="divider">/</span></li>
        <li class="active">公告板</li>
    </ul>

    <div class="container-fluid">

        <div class="row-fluid">

            <div class="block">
                <a href="#page-filter" class="block-heading" data-toggle="collapse">添加公告</a>
                <div id="page-filter" class="block-body collapse in">
                    <div class="search-well">
                        <form class="form-inline" role="search"
                              action="#" method="post">
                            <input type="text" class="form-control" placeholder="请输入图书ID"
                                   name="book_id"/>
                            <input type="text" class="form-control"
                                   placeholder="请输入公告内容" name="news_contents"/>

                            <button class="btn btn-primary" id="btnSave">
                                <i class="icon-save"></i> 保存
                            </button>

                        </form>
                    </div>
                </div>
            </div>
        </div>

        <div class="row-fluid">

            <span>共有 <b>${count}</b> 条记录</span>

            <div class="well">
                <table class="table">
                    <thead>
                    <tr id="theTableTitle">
                        <th>编号</th>
                        <th>公告内容</th>
                        <th>链接书籍ID</th>
                        <th>操作</th>
                    </tr>
                    </thead>

                    <tbody>
                    <c:forEach items="${newsInfoList}" var="newsInfo">
                        <tr>
                            <td>${newsInfo.newsId}</td>
                            <td>${newsInfo.newsTitle}</td>
                            <td>
                                链接书籍ID:{${newsInfo.bookId}}
                            </td>
                            <td>
                                <a href="${pageContext.request.contextPath}/ad/toupdatenew/${newsInfo.newsId}" title="编辑"><i class="icon-pencil"></i></a>
                                <a href="javascript:del(${newsInfo.newsId})" title="删除"><i class="icon-remove"></i></a>
                            </td>
                        </tr>
                    </c:forEach>


                    </tbody>

                </table>
            </div>
            <div class="pagination pagination myul">
                <ul>
                    <%--    首页上一页    --%>
                    <c:if test="${page>1}">
                        <li>
                            <a href="${pageContext.request.contextPath}/ad/adnews?page=1">&laquo;首页</a>
                        </li>
                        <li><a
                                href="${pageContext.request.contextPath}/ad/adnews?page=${page-1}">上一页</a>
                        </li>
                    </c:if>
                    <c:if test="${page<=1}">
                        <li class='disabled'><a href="javascript:">&laquo;首页</a></li>
                        <li class='disabled'><a href="javascript:">上一页</a></li>
                    </c:if>

                    <%--    页数   --%>
                    <c:forEach begin="1" end="${zoyeshu}" var="i">
                        <li ${i==page?"class='active'":""}>
                            <a href="${pageContext.request.contextPath}/ad/adnews?page=${i}">
                                    ${i}
                            </a>
                        </li>
                    </c:forEach>

                    <%--    末页下一页    --%>
                    <c:if test="${page<zoyeshu}">
                        <li>
                            <a href="${pageContext.request.contextPath}/ad/adnews?page=${page+1}">下一页</a>
                        </li>

                        <li>
                            <a href="${pageContext.request.contextPath}/ad/adnews?page=${zoyeshu}">尾页&raquo;</a>
                        </li>
                    </c:if>
                    <c:if test="${page>=zoyeshu}">
                        <li class='disabled'>
                            <a href="javascript:">下一页</a>
                        </li>

                        <li class='disabled'>
                            <a href="javascript:">尾页&raquo;</a>
                        </li>
                    </c:if>
                </ul>
            </div>


        </div>


        <!-- 底部 -->
        <c:import url="footer.jsp"></c:import>


    </div>


</div>

<script src="${pageContext.request.contextPath }/static/lib/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/lib/tooltips.js"></script>
<script type="text/javascript">
    $("[rel=tooltip]").tooltip();
    $(function () {
        $('.demo-cancel-click').click(function () {
            return false;
        });

        $("#btnSave").click(function () {
            var book_id = $("input[name='book_id']").val();
            var news_contents = $("input[name='news_contents']").val();
            if (book_id == '') {
                show_err_msg("请输入书籍ID");
            } else if (news_contents == '') {
                show_err_msg("请输入公告内容");
            } else {

                show_loading();

                var url = "${pageContext.request.contextPath}/ad/insertnew";
                var data = {
                    book_id: book_id,
                    news_contents: news_contents
                };
                $.post(url, data, function (response) {
                    if (response.msg) {
                        show_msg("添加成功", "${pageContext.request.contextPath }/ad/adnews");
                    } else {
                        show_err_msg('添加失败');
                    }

                });

            }

            return false;
        });
    });


    function del(news_id) {
        if (confirm("是否确定删除")) {
            var url = "${pageContext.request.contextPath}/ad/delnew";
            var data = {
                news_id: news_id
            };
            $.post(url, data, function (response) {
                if (response.msg) {
                    show_msg("删除成功", "${pageContext.request.contextPath }/ad/adnews");
                } else {
                    show_err_msg('删除失败');
                }
            });
        }
    }
</script>

</body>
</html>

